<template>
	<view>
		<view class="drop" v-show="clickShow">
			<view class="shape"></view>
			<view class="dropItem">
				<image src="../../static/tabimg/mima.png" class="imgCode"></image>
				<view @tap="changepass">修改密码</view>
			</view>
			<view class="dropItem">
				<image src="../../static/tabimg/tuichu.png" class="imgCode2"></image>
				<view @tap="close">退出应用</view>
			</view>
		</view>
		<!-- 主体内容 -->
		<map style="width: 100%; height: 100vh;" :latitude="latitude" :longitude="longitude" :markers="covers" @markertap="labelShow"
		 scale="6"></map>
	</view>
</template>

<script>
	import {
		post
	} from "../../lib/Util.js"
	import {
		mapState
	} from 'vuex'
	export default {
		data() {
			return {
				src: '',
				id: '',
				markerDatas: [],
				clickShow: false,
				title: 'map',
				latitude: 39.909,
				longitude: 116.39742,
				covers: [],
			}
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'userName']),
		onLoad() {
			this.getuserpro();
			uni.$on('popup-page', (data) => {
				uni.navigateTo({
					url: "../pojectinfo/pojectinfo?id=" + data.info + "&title=" + data.content
				})
			});
			if (!uni.getStorageSync('hasLogin')) {
				uni.showModal({
					title: '未登录',
					content: '您未登录，需要登录后才能继续',
					showCancel: !this.forcedLogin,
					success: (res) => {
						if (res.confirm) {
							if (this.forcedLogin) {
								uni.reLaunch({
									url: '../login/login'
								});
							} else {
								uni.navigateTo({
									url: '../login/login'
								});
							}
						}
					}
				});
			};
		},
		onUnload() {
			uni.$off('popup-page')
		},
		onNavigationBarButtonTap(e) {
			if (e.float == "right") {
				this.clickShow = !this.clickShow;
			}
		},
		methods: {
			async getuserpro() {
				let icon = {
					"1": "/static/tabimg/Img1.png",
					"2": "/static/tabimg/Img2.png",
					"3": "/static/tabimg/Img3.png",
					"4": "/static/tabimg/4.png",
					"5": "/static/tabimg/5.png",
					"6": "/static/tabimg/6.png",
					"7": "/static/tabimg/7.png",
					"8": "/static/tabimg/8.png",
					"9": "/static/tabimg/9.png",
					"10": "/static/tabimg/10.png",
					"11": "/static/tabimg/11.png",
					"12": "/static/tabimg/12.png",
					"13": "/static/tabimg/13.png",
					"14": "/static/tabimg/14.png",
					"15": "/static/tabimg/15.png"
				}
				let userid = uni.getStorageSync('userID');
				let data = {
					id: userid
				}
				let res = await post('map/findAll', data)
				if (typeof(res.data) !== 'string') {
					for (let i = 0; i < res.data.length; i++) {
						res.data[i]['id'] = i + 1
						this.covers.push({
							id: (i + 1),
							latitude: res.data[i].latitude,
							longitude: res.data[i].longitude,
							iconPath: icon[res.data[i].num]
						})
						this.markerDatas = res.data
					}
				}
			},
			labelShow(e) {
				var id = e.detail.markerId
				var marker
				this.markerDatas.map(o => {
					if (o.id == id) marker = o
				})
				uni.$emit('page-popup', {
					content: marker
				})
				const win = uni.getSubNVueById("subNVue")
				win.show("slide-in-bottom", 200)
			},
			close() {
				let _self = this;
				uni.showModal({
					title: '退出登录',
					content: '确定要退出吗？',
					success: function(res) {
						if (res.confirm) {
							console.log('用户点击确定');
							_self.logout();
							// #ifdef APP-PLUS  
							plus.runtime.quit();
							// #endif 
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});
			},
			changepass() {
				uni.navigateTo({
					url: '/pages/changepass/changepass'
				})
			},
			//搜索框
			getSearch() {
				let subSearch = uni.getSubNVueById('search')
				subSearch.show('fade-in')
			},
		},
	}
</script>

<style>

</style>
